package com.zb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zb.entity.TbUserModel;
import com.zb.mapper.TbUserMapper;
import com.zb.vo.LoginUser;
import kotlin.jvm.internal.Lambda;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailServiceImpl implements UserDetailsService {
    @Autowired
    private TbUserMapper tbUserMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        LambdaQueryWrapper<TbUserModel> qw = new LambdaQueryWrapper<>();
        qw.eq(TbUserModel::getNickname,username);
        TbUserModel tbUserModel = tbUserMapper.selectOne(qw);
        if (tbUserModel!=null) {
            return new LoginUser(tbUserModel);
        }
        return null;
    }
}
